﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using MbUnit.Framework;

namespace HelloMVC.Test.Selenium
{
    [TestFixture]
    public class DashboardPage
    {
        private IWebDriver Browser { get; set; }

        [TestFixtureSetUp]
        public void SetUp()
        {
            Browser = new FirefoxDriver();
            Browser.Navigate().GoToUrl("http://localhost/NIRA_DEV/DashBoard/Dashboard.mvc");
        }

        [TestFixtureTearDown]
        public void TearDown()
        {
            Browser.Close();
        }


        /// <summary>
        /// Test Case: Logo Display
        /// </summary>
        [Test("Logo Didplay: The logo should be HelloMVC")]
        public void TestLogo()
        {
            IWebElement logo = Browser.FindElement(By.Id("logo"));
            Assert.IsNotNull(logo);
            Assert.AreEqual("HelloMVC", logo.Text);
        }

        [Test("Log In Text Display")]
        public void TestLogInText()
        {
            IWebElement login = Browser.FindElement(By.Id("login"));
            Assert.IsNotNull(login);
            Assert.AreEqual("Log In", login.Text);
        }

        [Test("Navigator Bar Text Display")]
        public void TestNavigatorTextDisplay()
        {
            IWebElement navigator = Browser.FindElement(By.Id("main-nav"));
            Assert.IsNotNull(navigator);
            var navs = navigator.FindElements(By.XPath("li[*]/a"));
            Assert.AreEqual(4, navs.Count);

            var navTexts = new[] { "Dashboards", "Projects", "Issues", "Agile"};

            for (Int32 i = 0; i < navs.Count; i++)
            {
                Assert.AreEqual(navTexts[i], navs[i].Text);
            }
            
        }

        [Test("Introduction box display")]
        public void TestIntroductionBox()
        {
            IWebElement introductionBoxTitle = Browser.FindElement(By.Id("introduction-title"));
            Assert.AreEqual("Introduction", introductionBoxTitle.Text);
        }


        [Test("Quick Links Box display")]
        public void TestQuickLinksBox()
        {
            IWebElement quickLinksBoxTitle = Browser.FindElement(By.Id("quicklink-box-title"));
            Assert.AreEqual("Quick Links", quickLinksBoxTitle.Text);
        }

        [Test("Login Box display")]
        public void TestLoginBox()
        {
            IWebElement loginBoxTitle = Browser.FindElement(By.Id("loginbox-title"));
            Assert.AreEqual("Login", loginBoxTitle.Text);
        }

        [Test("Tools options")]
        public void TestToolsOptions()
        {
            IWebElement toolsOptions = Browser.FindElement(By.Id("dash-options"));
            Assert.IsNotNull(toolsOptions);
            IWebElement toolsText = toolsOptions.FindElement(By.XPath("span[1]"));
            Assert.AreEqual("Tools", toolsText.Text);
        }

    }
}
